import type { CrudConfig } from '@/features/share/crudtemplate/crudFactory'

const messageConfig: CrudConfig = {
  // 页面基本信息
  page: {
    title: '消息管理',
    description: '管理系统中的消息通知',
    permission: 'acl:message',
    targetNameField: 'title',
  },

  // API接口配置
  api: {
    GET_URL: '/messages/list',
    CREATE_URL: '/messages/save',
    UPDATE_URL: '/messages/update',
    DELETE_URL: '/messages/remove',
    BATCH_DELETE_URL: '/messages/batchRemove',
  },

  // 搜索配置
  search: {
    fields: [
      {
        prop: 'title',
        label: '标题',
        type: 'input',
        placeholder: '按标题搜索',
        clearable: true,
      },
      {
        prop: 'content',
        label: '内容',
        type: 'input',
        placeholder: '按内容搜索',
        clearable: true,
      },
      {
        prop: 'status',
        label: '状态',
        type: 'select',
        placeholder: '请选择状态',
        clearable: true,
        options: [
          { label: '启用', value: 'ACTIVE' },
          { label: '禁用', value: 'INACTIVE' },
        ],
      },
      {
        prop: 'pinned',
        label: '是否置顶',
        type: 'select',
        placeholder: '请选择',
        clearable: true,
        options: [
          { label: '否', value: false },
          { label: '是', value: true },
        ],
      },
    ],
  },

  // 表格列配置
  tableColumns: [
    {
      type: 'selection',
      label: '选择',
      width: 'auto',
      align: 'center',
    },
    {
      type: 'index',
      label: 'ID',
      width: 80,
      align: 'center',
    },
    {
      prop: 'title',
      label: '标题',
      minWidth: 'auto',
      align: 'center',
      showOverflowTooltip: true,
    },
    {
      prop: 'content',
      label: '内容',
      minWidth: 'auto',
      align: 'center',
      showOverflowTooltip: true,
    },
    {
      prop: 'user.nickName',
      label: '发布者',
      minWidth: 'auto',
      align: 'center',
      showOverflowTooltip: true,
    },
    {
      prop: 'status',
      label: '状态',
      type: 'tag',
      minWidth: 'auto',
      align: 'center',
      tagConfig: {
        textMap: {
          ACTIVE: '正常',
          INACTIVE: '停用',
        },
        typeMap: {
          ACTIVE: 'success',
          INACTIVE: 'warning',
        },
      },
    },
    {
      prop: 'pinned',
      label: '是否置顶',
      type: 'tag',
      minWidth: 'auto',
      align: 'center',
      tagConfig: {
        colorMap: {
          true: '#E6A23C',
          false: '#909399',
        },
        textMap: {
          true: '是',
          false: '否',
        },
      },
    },
    {
      prop: 'createdAt',
      label: '创建时间',
      type: 'date',
      width: 180,
      align: 'center',
      sortable: true,
      dateConfig: {
        format: 'YYYY-MM-DD HH:mm:ss',
      },
    },
  ],

  // 表格操作列配置
  tableActionColumn: {
    width: 'auto',
    align: 'center',
    fixed: 'right',
  },

  // 表格操作列按钮配置
  tableActions: [
    {
      text: '编辑',
      label: '编辑',
      type: 'primary',
      size: 'small',
      plain: true,
      permission: 'btn.Message.update',
      action: 'edit',
    },
    {
      text: '删除',
      label: '删除',
      type: 'danger',
      size: 'small',
      plain: true,
      permission: 'btn.Message.remove',
      action: 'delete',
    },
  ],

  // 表单配置
  form: {
    fields: [
      {
        prop: 'title',
        label: '标题',
        type: 'input',
        placeholder: '请输入标题',
        required: true,
        maxlength: 100,
        showWordLimit: true,
      },
      {
        prop: 'content',
        label: '内容',
        type: 'textarea',
        placeholder: '请输入内容',
        required: true,
        maxlength: 500,
        showWordLimit: true,
        rows: 4,
      },
      {
        prop: 'status',
        label: '状态',
        type: 'select',
        required: true,
        options: [
          { label: '启用', value: 'ACTIVE' },
          { label: '禁用', value: 'INACTIVE' },
        ],
      },
      {
        prop: 'pinned',
        label: '是否置顶',
        type: 'select',
        options: [
          { label: '否', value: false },
          { label: '是', value: true },
        ],
      },
    ],
    rules: {
      title: [
        { required: true, message: '请输入标题', trigger: 'blur' },
        { min: 1, max: 100, message: '标题长度在 1 到 100 个字符', trigger: 'blur' },
      ],
      content: [
        { required: true, message: '请输入内容', trigger: 'blur' },
        { min: 1, max: 500, message: '内容长度在 1 到 500 个字符', trigger: 'blur' },
      ],
      status: [{ required: true, message: '请选择状态', trigger: 'change' }],
    },
    labelWidth: '100px',
    dialogWidth: '600px',
    addTitle: '新增消息',
    editTitle: '编辑消息',
  },

  // 操作按钮配置
  actions: {
    add: {
      text: '新增消息',
      icon: 'Plus',
      permission: 'btn.Message.add',
    },
    batchDelete: {
      text: '批量删除',
      icon: 'Delete',
      permission: 'btn.Message.batchRemove',
    },
  },

  // 分页配置
  pagination: {
    pageSizes: [10, 20, 50, 100],
    defaultPageSize: 10,
  },

  // 消息配置
  messages: {
    loadSuccess: '消息获取成功',
    addSuccess: '消息添加成功！',
    editSuccess: '消息修改成功！',
  },
}

export default messageConfig
